function memoize(f) {
  const cache = new Map();
  return function (...args) {
    let key = JSON.stringify(args);
    if (!cache.has(key)) {
      cache.set(key, f.apply(this, args));
    }
    return cache.get(key);
  };
}
function gcd(a, b) {
  console.log(`call gcd(${a}, ${b})`);
  if (a < b) {
    [a, b] = [b, a];
  }
  while (b !== 0) {
    [a, b] = [b, a % b];
  }
  return a;
}
const gcdmemo = memoize(gcd);
// 下面只会打印一次 call gcd(85, 187)
console.log(gcdmemo(85, 187)); // 17
console.log(gcdmemo(85, 187)); // 17
